package org.bing.flex.action {

    import mx.messaging.ChannelSet;
    import mx.messaging.channels.AMFChannel;
    import mx.rpc.AsyncToken;
    import mx.rpc.remoting.mxml.Operation;
    import mx.rpc.remoting.mxml.RemoteObject;

    public class GraniteAction extends GeneralAction {
        private var service:String;
        private var channel:ChannelSet;

        public function GraniteAction(srv:String):void {
            this.service=srv;
            var chl:AMFChannel=new AMFChannel("AmfOnHttp", url());
            this.channel=new ChannelSet();
            channel.addChannel(chl);
        }

        override public function invoke(method:String, args:Array=null, onResult:Function=null, onFault:Function=null):void {
            var remote:RemoteObject=new RemoteObject(service);
            remote.channelSet=channel;

            var operation:Operation=remote.getOperation(method) as Operation;
            if (args) {
                operation.arguments=(args is Array) ? args : [args];
            }
            var responder:GraniteResponder=new GraniteResponder(onResult);
            var caller:AsyncToken=operation.send();
            caller.addResponder(responder);
        }
    }
}